<template>
  <!-- 过程评价管理 -->
  <div>
    <InnerBreadcrumb v-model="indexKey" :path="breadPath" :showBack="true"/>
    <div class="edu-page-warp"  v-if="indexKey === '1'">
      <condition-card @reset="reset" @search="searchList" :label-width="labelWidth" style="margin-bottom: 20px;">
        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item label="学院">
              <DictSelect
                labelAll="请选择"
                :disabled="facultyDisable"
                filterable multiple collapse-tags
                v-model="queryParams.facultyList"
                :data="options.faculty"
                @change="handleChangeFaculty"
              ></DictSelect>
            </el-form-item>
          </el-col>
          <!-- 校区 -->
          <el-col :span="8">
            <el-form-item :label="$t('校区')">
              <dict-select
                v-model="queryParams.campusList"
                label-all="请选择"
                multiple collapse-tags
                :data="options.campusList">
              </dict-select>
            </el-form-item>
          </el-col>
          <!-- 年级 -->
          <el-col :span="8">
            <el-form-item label="年级">
              <el-select v-model="queryParams.gradeList" multiple
                collapse-tags filterable clearable style="width: 100%">
                <el-option v-for="item in options.grade" :key="item.value"
                  :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <!-- 专业 -->
          <el-col :span="8">
            <el-form-item label="专业">
                <DictSelect
                    labelAll="请选择"
                    v-model="queryParams.professionList"
                    :data="options.profession"
                    filterable
                    multiple
                    collapse-tags
                    clearable
                ></DictSelect>
            </el-form-item>
          </el-col>
          <!-- 培养类别 -->
          <el-col :span="8">
            <el-form-item :label="$t('label.trainingCategory')">
              <el-select v-model="queryParams.trainingCategoryList"
                filterable multiple collapse-tags
                clearable
                style="width: 100%;">
                <el-option
                  v-for="item in options.trainingCategory"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- 培养层次 -->
          <el-col :span="8">
            <el-form-item :label="$t('label.trainingLevel')" prop="trainingLevel">
              <dict-select
                multiple collapse-tags
                labelAll="请选择"
                v-model="queryParams.trainingLevelList"
                :data="options.trainingLevelList"
                :show-all="false"
                clearable
                @change="getCourseCodeList"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <!-- 学位类型 -->
          <el-col :span="8">
            <el-form-item label="学位类型">
              <el-select v-model="queryParams.degreeTypeList"
                clearable multiple collapse-tags style="width: 100%">
                <el-option v-for="item in options.degreeType" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- 学习形式 -->
          <el-col :span="8">
            <el-form-item label="学习形式">
              <DictSelect
                multiple collapse-tags
                labelAll="请选择"
                v-model="queryParams.formLearningList"
                :data="options.formLearning"
              ></DictSelect>
            </el-form-item>
          </el-col>
          <!-- 入学季节 -->
          <el-col :span="8">
            <el-form-item label="入学季节" prop="enrolSeason">
              <el-select
                multiple collapse-tags
                v-model="queryParams.enrolSeasonList"
                style="width: 100%"
                clearable>
                <el-option
                  v-for="item in options.enrolSeason"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <!-- 状态 -->
          <el-col :span="8">
            <el-form-item label="状态" prop="enrolSeason">
              <el-select
                v-model="queryParams.releaseState"
                style="width: 100%"
                clearable>
                <el-option
                  v-for="item in statusList"
                  :key="item.code"
                  :label="item.statusName"
                  :value="item.code"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </condition-card>

      <!-- 表格card -->
      <el-card shadow="never">
        <div class="edu-page-title">{{title}}</div>
        <div class="edu-opertion-bar">
          <div class="float-left">
          <KeywordInput
            v-model="queryParams.managementName"
            :placeholder="$t('请输入主题名')"
            @enter="searchList"/>
          </div>
          <div class="float-right">
            <el-button @click="fullScreenClick()">{{$t('全屏查看')}}</el-button>
            <el-button type="primary" @click="exportData()">{{$t('message.export')}}</el-button>
            <el-button type="primary" v-if="!ifFacultyUser" @click="addClick()">{{$t('message.add')}}</el-button>
          </div>
        </div>
        <!-- 主页表格 -->
        <edu-table :url="url" ref="mainTable" :order="true" :selection="true">
          <edu-table-column :label="$t('过程评价主题名')" min-width="120px">
            <template slot-scope="scope">
              <el-button type="text" @click="themeClick(scope.row)">{{scope.row.managementName}}</el-button>
            </template>
          </edu-table-column>
          <edu-table-column :label="$t('学院')" prop="facultyName"></edu-table-column>
          <edu-table-column :label="$t('校区')" prop="campusName"></edu-table-column>
          <edu-table-column :label="$t('年级')" prop="grade"></edu-table-column>
          <edu-table-column :label="$t('专业')" prop="professionName"></edu-table-column>
          <edu-table-column :label="$t('培养层次')" prop="trainingLevelName"></edu-table-column>
          <edu-table-column :label="$t('培养类别')" prop="trainingCategoryName"></edu-table-column>
          <edu-table-column :label="$t('学位类型')" prop="degreeTypeName"></edu-table-column>
          <edu-table-column :label="$t('学习形式')" prop="fromLearningName"></edu-table-column>
          <edu-table-column :label="$t('入学季节')" prop="enrolSeasonName"></edu-table-column>
          <edu-table-column :label="$t('过程评价开始时间')" prop="startTime" min-width="140px"></edu-table-column>
          <edu-table-column :label="$t('过程评价结束时间')" prop="endTime" min-width="140px"></edu-table-column>
          <edu-table-column :label="$t('是否强制')">
            <template slot-scope="scope">
              <el-switch :disabled="ifFacultyUser" @change="changeForceState(scope.row)" :value="scope.row.forceState" active-value="1" inactive-value="0"></el-switch>
            </template>
          </edu-table-column>
          <edu-table-column :label="$t('状态')">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.releaseState === '0'" type="danger">
                {{ `未发布` }}
              </el-tag>
              <el-tag v-if="scope.row.releaseState === '1'" type="info">
                {{ `已完成` }}
              </el-tag>
              <el-tag v-if="scope.row.releaseState === '2'" type="success">
                {{ `已发布` }}
              </el-tag>
              <el-tag v-if="scope.row.releaseState === '3'" type="warning">
                {{ `已撤销` }}
              </el-tag>
            </template>
          </edu-table-column>
          <edu-table-column :label="$t('message.operating')" min-width="220px">
            <template slot-scope="scope">
              <el-button type="text" v-if="(scope.row.releaseState === '0' || scope.row.releaseState === '3') && !ifFacultyUser" @click.stop="editClick(scope.row)">{{$t('编辑')}}</el-button>
              <el-button type="text" v-if="(scope.row.releaseState === '0' || scope.row.releaseState === '3') && !ifFacultyUser" @click.stop="releaseClick(scope.row)">{{$t('发布')}}</el-button>
              <el-button type="text" v-if="(scope.row.releaseState === '0' || scope.row.releaseState === '3') && !ifFacultyUser" @click.stop="deleteClick(scope.row)">{{$t('删除')}}</el-button>
              <el-button type="text" @click.stop="previewClick(scope.row)">{{$t('预览')}}</el-button>
              <el-button type="text" v-if="scope.row.releaseState === '2' && !ifFacultyUser" @click.stop="withdrawClick(scope.row)">{{$t('撤销')}}</el-button>
              <el-button type="text" v-if="scope.row.releaseState !== '0'" @click.stop="checkClick(scope.row)">{{$t('查看')}}</el-button>
            </template>
          </edu-table-column>
        </edu-table>
        <edu-export-dialog :disabled="exportButton" :title="$t('message.prompt')" ref="downloadRef" :data="exportResult"></edu-export-dialog>
      </el-card>
    </div>
    <div v-if="indexKey === '2'">
      <QuestionnaireThemeOfProcessStu :ifRelease="ifRelease"></QuestionnaireThemeOfProcessStu>
    </div>
    <!-- 新增/编辑 -->
    <div v-if="indexKey === '3'">
      <AddQuestionaireOfProcessStu
        @goToAddNext="goToAddNext"
        @onlyGoBack="onlyGoBack"
        :ifEdit="ifEdit"
        :ifPrev="ifPrev"
        @goToPreview="goToPreview">
      </AddQuestionaireOfProcessStu>
    </div>
    <div v-if="indexKey === '4'">
      <QuestionsPreview
        :data="questionList"
        :typeTitle="'预览'"
        :title="childTitle"
        :foreword="foreword"
        :pageType="'preview'"
        :maintainShow="false"
        :exportShow="false">
      </QuestionsPreview>
    </div>
    <div v-if="indexKey === '5'">
      <ObjectSetProcessStu
        :ifEdit="ifEdit"
        @editGoBack="editGoBack"
        @onlyGoBack="onlyGoBack"
        @goToAddOrEdit="goToAddOrEdit">
      </ObjectSetProcessStu>
    </div>
    <div v-if="indexKey === '6'">
      <CheckResult :checkData="checkData" :ifProcess="ifProcess"></CheckResult>
    </div>
    <edu-dialog
      :title="'预览'"
      ref="templateDialog"
      :width="'80%'"
      :showFooter="false"
      :showButtons="true"
      :showConfirmBtn="false"
      @close="templateDialogClose">
      <QuestionsPreview
        :data="questionList"
        :title="childTitle"
        :pageType="'preview'"
        :foreword="foreword"
        :maintainShow="false"
        :exportShow="false">
      </QuestionsPreview>
    </edu-dialog>
    <!-- 全屏查看 -->
    <edu-dialog
      :title="'全屏查看'"
      ref="fullScreenDialog"
      :width="'90%'"
      :showFooter="false"
      :showButtons="true"
      :showConfirmBtn="false"
      @close="fullScreenDialogClose">
      <condition-card @reset="fullReset" @search="fullSearchList" :label-width="labelWidth" style="margin-bottom: 20px;">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="学院">
              <DictSelect
                labelAll="请选择"
                :disabled="facultyDisable"
                filterable multiple collapse-tags
                v-model="fullQueryParams.facultyList"
                :data="options.faculty"
                @change="handleChangeFaculty"
              ></DictSelect>
            </el-form-item>
          </el-col>
          <!-- 校区 -->
          <el-col :span="8">
            <el-form-item :label="$t('校区')">
              <dict-select
                v-model="fullQueryParams.campusList"
                label-all="请选择"
                multiple collapse-tags
                :data="options.campusList">
              </dict-select>
            </el-form-item>
          </el-col>
          <!-- 年级 -->
          <el-col :span="8">
            <el-form-item label="年级">
              <el-select v-model="fullQueryParams.gradeList" multiple
                collapse-tags filterable clearable style="width: 100%">
                <el-option v-for="item in options.grade" :key="item.value"
                  :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- 专业 -->
          <el-col :span="8">
            <el-form-item label="专业">
                <DictSelect
                    labelAll="请选择"
                    v-model="fullQueryParams.professionList"
                    :data="options.profession"
                    filterable
                    multiple
                    collapse-tags
                    clearable
                ></DictSelect>
            </el-form-item>
          </el-col>
          <!-- 培养类别 -->
          <el-col :span="8">
            <el-form-item :label="$t('label.trainingCategory')">
              <el-select v-model="fullQueryParams.trainingCategoryList"
                filterable multiple collapse-tags
                clearable
                style="width: 100%;">
                <el-option
                  v-for="item in options.trainingCategory"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- 培养层次 -->
          <el-col :span="8">
            <el-form-item :label="$t('label.trainingLevel')" prop="trainingLevel">
              <dict-select
                multiple collapse-tags
                labelAll="请选择"
                v-model="fullQueryParams.trainingLevelList"
                :data="options.trainingLevelList"
                :show-all="false"
                clearable
                @change="getCourseCodeList"
              />
            </el-form-item>
          </el-col>
          <!-- 学位类型 -->
          <el-col :span="8">
            <el-form-item label="学位类型">
              <el-select v-model="fullQueryParams.degreeTypeList"
                clearable multiple collapse-tags style="width: 100%">
                <el-option v-for="item in options.degreeType" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- 学习形式 -->
          <el-col :span="8">
            <el-form-item label="学习形式">
              <DictSelect
                multiple collapse-tags
                labelAll="请选择"
                v-model="fullQueryParams.formLearningList"
                :data="options.formLearning"
              ></DictSelect>
            </el-form-item>
          </el-col>
          <!-- 入学季节 -->
          <el-col :span="8">
            <el-form-item label="入学季节" prop="enrolSeason">
              <el-select
                multiple collapse-tags
                v-model="fullQueryParams.enrolSeasonList"
                style="width: 100%"
                clearable>
                <el-option
                  v-for="item in options.enrolSeason"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- 状态 -->
          <el-col :span="8">
            <el-form-item label="状态" prop="enrolSeason">
              <el-select
                v-model="fullQueryParams.releaseState"
                style="width: 100%"
                clearable>
                <el-option
                  v-for="item in statusList"
                  :key="item.code"
                  :label="item.statusName"
                  :value="item.code"/>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- 主题名 -->
          <el-col :span="8">
            <el-form-item label="问卷主题名" prop="managementName">
              <el-input v-model="fullQueryParams.managementName" placeholder="请输入" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </condition-card>
      <edu-table :url="url" ref="fullScreenTable" border :selection="false" class="full-screen-table">
        <edu-table-column align="center" :label="$t('过程评价主题名')" min-width="120px">
          <template slot-scope="scope">
            <el-button type="text" disabled @click="themeClick(scope.row)">{{scope.row.managementName}}</el-button>
          </template>
        </edu-table-column>
        <edu-table-column align="center" :label="$t('学院')" prop="facultyName"></edu-table-column>
        <edu-table-column align="center" :label="$t('校区')" prop="campusName"></edu-table-column>
        <edu-table-column align="center" :label="$t('年级')" prop="grade"></edu-table-column>
        <edu-table-column align="center" :label="$t('专业')" prop="professionName"></edu-table-column>
        <edu-table-column align="center" :label="$t('培养层次')" prop="trainingLevelName"></edu-table-column>
        <edu-table-column align="center" :label="$t('培养类别')" prop="trainingCategoryName"></edu-table-column>
        <edu-table-column align="center" :label="$t('学位类型')" prop="degreeTypeName"></edu-table-column>
        <edu-table-column align="center" :label="$t('学习形式')" prop="fromLearningName"></edu-table-column>
        <edu-table-column align="center" :label="$t('入学季节')" prop="enrolSeasonName"></edu-table-column>
        <edu-table-column align="center" :label="$t('过程评价开始时间')" prop="startTime" min-width="140px"></edu-table-column>
        <edu-table-column align="center" :label="$t('过程评价结束时间')" prop="endTime" min-width="140px"></edu-table-column>
        <edu-table-column :label="$t('是否强制')">
          <template slot-scope="scope">
            <div style="display: flex;justify-content: center;align-items: center;">
              <span v-if="scope.row.forceState === '1'">是</span>
              <span v-else>否</span>
            </div>
          </template>
        </edu-table-column>
        <edu-table-column align="center" :label="$t('状态')">
          <template slot-scope="scope">
            <div style="display: flex;text-align: center;">
              <el-tag v-if="scope.row.releaseState === '0'" type="danger">
                {{ `未发布` }}
              </el-tag>
              <el-tag v-if="scope.row.releaseState === '1'" type="info">
                {{ `已完成` }}
              </el-tag>
              <el-tag v-if="scope.row.releaseState === '2'" type="success">
                {{ `已发布` }}
              </el-tag>
              <el-tag v-if="scope.row.releaseState === '3'" type="warning">
                {{ `已撤销` }}
              </el-tag>
            </div>
          </template>
        </edu-table-column>
      </edu-table>
    </edu-dialog>
  </div>

</template>
<script>
import baseUrl from 'common/src/api/teachingEvaluation/env'
import innovativeApi from 'common/src/api/innovative/innovative'
import { queryDic } from "common/src/api/dictionary"
import UTILS from "common/src/utils/utils";
import QuestionnaireThemeOfProcessStu from './component/QuestionnaireThemeOfProcessStu'
import processEvaluationApi from 'common/src/api/teachingEvaluation/processEvaluation'
import AddQuestionaireOfProcessStu from './component/AddQuestionaireOfProcessStu'
import ObjectSetProcessStu from './component/ObjectSetProcessStu'
import courseEvaluationApi from 'common/src/api/teachingEvaluation/courseEvaluation'
import QuestionsPreview from './component/QuestionnairePreview/QuestionsPreview'
import templateApi from 'common/src/api/teachingEvaluation/template'
import CheckResult from './component/CheckResult'
export default {
  components: {
    QuestionnaireThemeOfProcessStu,
    AddQuestionaireOfProcessStu,
    ObjectSetProcessStu,
    QuestionsPreview,
    CheckResult
  },
  data() {
    const getGrade = (function() {
      let now = new Date().getFullYear();
      let years = [];
      for (let i = 0; i < 18; i++) {
        years.push({
          label: now - i,
          value: now - i
        });
      }
      return years;
    })();
    return {
      url: `${baseUrl}/processStudent/getPageList`,
      title: '过程评价问卷列表',
      dialogTitle: '新增',
      labelWidth: '120px',
      exportButton: false,
      exportResult: null,
      ifProcess: true,
      checkData: {},
      // facultyList: [],
      options: {
        campusList: [],
        faculty: [],
        grade: getGrade,
        trainingLevelList: [],
        trainingCategory: [],
        degreeType: [],
        formLearning: [],
        enrolSeason: [],
        profession: [] // 专业
      },
      processForm: {
        managementName: '',
        templateMainId: '',
        startTime: '',
        endTime: '',
        introduction: ''
      },
      ifEdit: false,
      indexKey: '1',
      breadPath: {
        label: this.$t('过程评价管理'),
        key: "1",
        children: [
          {
            key: "2",
            label: this.$t('问卷主题')
          },
          {
            key: "3",
            label: this.$t('新增'),
            children: [
              {
                key: "5",
                label: this.$t('过程评价对象配置')
              }
            ]
          },
          {
            key: "4",
            label: this.$t('预览')
          },
          {
            key: "6",
            label: this.$t('查看')
          }
        ]
      },
      queryParams: {
        campusList: [],
        gradeList: [],
        enrolSeasonList: [],
        trainingLevelList: [],
        facultyList: [],
        trainingCategoryList: [],
        degreeTypeList: [],
        professionList: [],
        formLearningList: [],
        managementName: '',
        releaseState: ''
      },
      fullQueryParams: {
        campusList: [],
        gradeList: [],
        enrolSeasonList: [],
        trainingLevelList: [],
        facultyList: [],
        trainingCategoryList: [],
        degreeTypeList: [],
        professionList: [],
        formLearningList: [],
        managementName: '',
        releaseState: ''
      },
      statusList: [
        {
          statusName: '未发布',
          code: 0
        },
        {
          statusName: '已完成',
          code: 1
        },
        {
          statusName: '已发布',
          code: 2
        },
        {
          statusName: '已撤销',
          code: 3
        }
      ],
      questionList: [],
      childTitle: '',
      ifPrev: false, // 是否上一步进入新增页面
      ifRelease: true,
      ifFacultyUser: false,
      facultyDisable: false
    }
  },
  created() {
    // this.getFaculty()
    courseEvaluationApi.judgeLoginRole().then(res => {
      if (res.data) {
        this.ifFacultyUser = true
        this.facultyDisable = true
        for (let key in res.data) {
          sessionStorage.setItem('currFacultyCode', key)
          this.queryParams.facultyList.push(key)
          this.fullQueryParams.facultyList.push(key)
        }
      } else {
        this.ifFacultyUser = false
        this.facultyDisable = false
        sessionStorage.setItem('currFacultyCode', '')
      }
      this.handleChangeFaculty()
    })
    this.getOptions()
    this.$router.push({
      query: {}
    });
  },
  mounted() {
    this.searchList()
  },
  methods: {
   // 查询
    searchList() {
      this.$refs.mainTable.pageNum = 1;
      this.$refs.mainTable.search(this.queryParams);
    },
    fullSearchList() {
      this.$refs.fullScreenTable.pageNum = 1;
      this.$refs.fullScreenTable.search(this.fullQueryParams);
    },
    getOptions() {
      //筛选条件字典查询
      let data = {
        lang: this.$store.getters.language || "cn",
        type: "allChild",
        keys: [
          "X_XQ", // 校区
          "X_PYLB", // 培养类别
          "X_PYCC", // 培养层次
          "X_XWLX", // 学位类型
          "X_XXXS", // 学习形式
          "X_RXJJ", // 入学季节
          "X_YX"
        ]
      };
      queryDic(data).then(res => {
        UTILS.fillSelect(
          {
            campusList: "X_XQ",
            // majors:"G_ZY",
            trainingCategory: "X_PYLB", // 培养类别
            trainingLevelList: "X_PYCC", // 培养层次
            degreeType: "X_XWLX", // 学位类型
            formLearning: "X_XXXS", // 学习形式
            enrolSeason: "X_RXJJ",
            faculty: "X_YX"
          },
          res.data,
          this.options
        );
      });
    },
    // 重置查询参数
    reset() {
      for (const key in this.queryParams) {
        if (key === 'releaseState' || key === 'managementName') {
          this.queryParams[key] = "";
        } else {
          this.queryParams[key] = [];
        }
      }
      if (this.facultyDisable) {
        this.queryParams.facultyList.push(sessionStorage.getItem('currFacultyCode'))
      }
      this.searchList()
    },
    fullReset() {
      for (const key in this.fullQueryParams) {
        if (key === 'releaseState' || key === 'managementName') {
          this.fullQueryParams[key] = "";
        } else {
          this.fullQueryParams[key] = [];
        }
      }
      if (this.facultyDisable) {
        this.fullQueryParams.facultyList.push(sessionStorage.getItem('currFacultyCode'))
      }
      this.fullSearchList()
    },
    // 查看点击
    checkClick(row) {
      const param = {
        managementId: row.managementId
      }
      processEvaluationApi.studentProcessReview(param).then(res => {
        this.checkData = res.data
        this.$nextTick(() => {
          this.indexKey = '6'
        })
      })
    },
    // 主题点击
    themeClick(row) {
      if (row.releaseState == '0') {
        this.$confirm("问卷未发布，是否确认查看?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.ifRelease = false
          this.$router.push({
            query: {
              managementId: row.managementId,
              calendarId: this.queryParams.calendarId
            }
          })
          this.indexKey = '2';
        })
      } else {
        this.ifRelease = true
        this.$router.push({
          query: {
            managementId: row.managementId,
            calendarId: this.queryParams.calendarId
          }
        })
        this.indexKey = '2';
      }
    },
    // 删除点击
    deleteClick(row) {
      let param = {
        managementId: row.managementId
      }
      let tip = '是否确认删除？'
      processEvaluationApi.judgeIfStudentProcessEvaWrite(param).then(res => {
        if (res.data) {
          tip = '已有人填写该问卷，是否确认删除？'
        } else {
          tip = '是否确认删除？'
        }
        this.$confirm(this.$t(tip), this.$t("message.prompt"), {
          confirmButtonText: this.$t("message.confirm"),
          cancelButtonText: this.$t("message.cancel"),
          type: "warning"
        }).then(() => {
          processEvaluationApi.deleteStudentProcessEva(param).then(res => {
            if (res.code === 200) {
              this.$message.success('删除成功');
              this.searchList();
            }
          })
        })
      })
    },
    // 重置表单
    resetProcessForm() {
      this.processForm = {
        managementName: '',
        templateMainId: '',
        startTime: '',
        endTime: '',
        introduction: ''
      }
    },
    // 关闭弹窗
    teachDialogClose() {
      this.$refs.processForm.clearValidate();
      this.$refs.teachDialog.close()
      this.resetProcessForm()
    },
    // 新增点击
    addClick() {
      this.breadPath.children[1].label = this.$t('新增')
      this.ifEdit = false
      this.ifPrev = false
      this.indexKey = '3';
    },
    // 编辑点击
    editClick(row) {
      this.breadPath.children[1].label = this.$t('编辑')
      this.ifEdit = true
      this.ifPrev = false
      this.indexKey = '3';
      this.$router.push({
        query: {
          managementId: row.managementId,
          calendarId: this.queryParams.calendarId,
          ifWithdraw: row.releaseState === '3' ? true : false
        }
      })
    },
    // 下一步
    nextStep() {
      this.indexKey = '3';
    },
    // 新增时子组件点击下一步 进入对象设置页面
    goToAddNext() {
      this.indexKey = '5';
    },
    // 新增取消时 返回当前页面
    onlyGoBack() {
      this.indexKey = '1';
    },
    // 编辑页面返回上一级
    editGoBack() {
      this.ifEdit = true
      this.ifPrev = false
      this.indexKey = '3';
    },
    // 对象配置返回上一级
    goToAddOrEdit() {
      this.ifEdit = false
      this.ifPrev = true
      this.indexKey = '3';
    },
    // 发布click
    releaseClick(row) {
      this.$confirm(this.$t('确定要发布问卷吗？'), this.$t("message.prompt"), {
        confirmButtonText: this.$t("message.confirm"),
        cancelButtonText: this.$t("message.cancel"),
        type: "warning"
      }).then(() => {
        let param = {
          managementId: row.managementId,
          templateMainId: row.templateMainId
        }
        processEvaluationApi.releaseStudentProcessEva(param).then(res => {
          if (res.code === 200) {
            this.$message.success('发布成功');
            this.searchList();
          }
        })
      });
    },
    // 强制
    changeForceState(row) {
      if (row.forceState === '1') {
        let param = {
          forceState: '0',
          managementId: row.managementId
        }
        processEvaluationApi.forceStudentProcessEva(param).then(res => {
          if (res.code === 200) {
            this.$message.success('已取消强制');
            this.$refs.mainTable.search(this.queryParams);
          }
        })
      } else if (row.forceState === '0') {
        let param = {
          forceState: '1',
          managementId: row.managementId
        }
        processEvaluationApi.forceStudentProcessEva(param).then(res => {
          if (res.code === 200) {
            this.$message.success('已强制');
            this.$refs.mainTable.search(this.queryParams);
          }
        })
      }
      // this.$confirm(this.$t('确定要强制执行该问卷吗？'), this.$t("message.prompt"), {
      //   confirmButtonText: this.$t("message.confirm"),
      //   cancelButtonText: this.$t("message.cancel"),
      //   type: "warning"
      // }).then(() => {
      // })
    },
    // 关闭弹窗
    templateDialogClose() {
      this.$refs.templateDialog.close()
    },
    // 全屏查看
    fullScreenClick() {
      this.$refs.fullScreenDialog.open()
      this.$nextTick(() => {
        if (this.ifFacultyUser) {
          this.fullQueryParams.facultyList.push(sessionStorage.getItem('currFacultyCode'))
          this.fullQueryParams.facultyList = Array.from(new Set(this.fullQueryParams.facultyList))
        }
        this.fullSearchList()
      })
    },
    fullScreenDialogClose() {
      this.$refs.fullScreenDialog.close()
      this.fullReset()
    },
    // 新增时预览模板
    goToPreview(value) {
      this.$router.push({
        query: {
          id: value.templateMainId,
          name: value.templateMainName,
          managementId: value.managementId,
          calendarId: value.calendarId,
          ifProcess: true
        }
      })
      let param = {
        id: value.templateMainId
      }
      this.childTitle = value.managementName
      this.foreword = value.introduction
      templateApi.getQuestionDetail(param).then(res => {
        if (res.code === 200) {
          this.questionList = res.data
          this.questionList.forEach(item => {
            // titleType: {1.单选 2.多选 3.问答}
            if (item['options']) {
              item['options'] = JSON.parse(item['options'])
            }
          })
          this.$refs.templateDialog.open()
        }
      })
    },
    // 预览click
    previewClick(row) {
      this.$router.push({
        query: {
          id: row.templateMainId,
          name: row.templateMainName,
          ifProcess: true
        }
      })
      let param = {
        id: row.templateMainId
      }
      this.childTitle = row.managementName
      this.foreword = row.introduction
      templateApi.getQuestionDetail(param).then(res => {
        if (res.code === 200) {
          this.questionList = res.data
          this.questionList.forEach(item => {
            // titleType: {1.单选 2.多选 3.问答}
            if (item['options']) {
              item['options'] = JSON.parse(item['options'])
            }
          })
        }
      })
      this.indexKey = '4'
    },
    // 撤销
    withdrawClick(row) {
      let param = {
        managementId: row.managementId
      }
      this.$confirm(this.$t('result.sureWithdrawData'), this.$t("message.prompt"), {
        confirmButtonText: this.$t("message.confirm"),
        cancelButtonText: this.$t("message.cancel"),
        type: 'warning'
      }).then(_ => {
        processEvaluationApi.withdrawStudentProcessEva(param).then(res => {
          if (res.code === 200) {
            this.$message.success('撤销成功');
            this.searchList();
          }
        })
      });
    },
    // 导出
    exportData() {
      if (this.$refs.mainTable.getData().length <= 0) {
        this.$message.error(this.$t('result.noExportData'));
        return;
      }
      const checkDatas = this.$refs.mainTable.getCheckData();
      let ids = checkDatas.map(item => {
        return item.managementId
      })
      let param = JSON.parse(JSON.stringify(this.queryParams))
      param.managementIdList = ids
      this.exportResult = null;
      this.$refs.downloadRef.open();
      this.exportButton = true;
      processEvaluationApi.exportStuProcess(param).then(res =>{
        if (res.code == 200) {
          this.delayRequest(res.data.key);
        } else {
          this.$refs.downloadRef.close();
          this.exportButton = false;
        }
      })
    },
    // 导出异步
    delayRequest(key) {
      setTimeout(() => {
        courseEvaluationApi.exportStatus(key).then(res => {
          this.exportResult = res.data;
          if (res.code == 200 && res.data.status) {
            this.exportButton = false;
            let path =
              `${baseUrl}/file/exportExcel?path=` +
              res.data.path;
            // window.open(path);
            window.location.href = path;
            this.$message.success(this.$t('result.exportSuccessfully'));
            this.$refs.downloadRef.close();
          } else {
            this.delayRequest(key);
          }
        });
      }, 3000);
    },
    // 根据学院获取专业
    handleChangeFaculty(val) {
      this.options.profession = [];
      this.queryParams.professionList = [];
      this.fullQueryParams.professionList = [];
      // this.query.currentProfession = "";
      let facultys_ = [];
      facultys_ = JSON.parse(JSON.stringify(this.queryParams.facultyList))
      const data = {
        lang: this.$store.getters.language || "cn",
        type: "allChild",
        keys: ["G_ZY"],
        filter: {
          specilaCode: "XY2ZY",
          facultys: facultys_
        }
      };
      queryDic(data).then(res => {
        if (res.code === 200)
          UTILS.fillSelect(
            {
              profession: "G_ZY"
            },
            res.data,
            this.options
          );
      });
    }
  },
  watch: {
    indexKey(value) {
      if (value == '1') {
        this.$router.push({
          query: {}
        })
        this.$nextTick(() => {
          this.searchList();
        })
      }
    }
  }
}
</script>
<style lang="scss">
.full-screen-table {
  .el-table .cell {
    white-space: pre-wrap
  }
}
</style>
